package cc.bluemc.modules.adminUser.entity;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import cc.bluemc.platform.annotation.fieldFormart.FieldFormart;
import org.apache.commons.lang.math.RandomUtils;

import cc.bluemc.modules.adminUser.service.RoleService;
import cc.bluemc.platform.annotation.fieldFormart.FieldFormart;
import cc.bluemc.platform.utils.BeanUtil;

@Table(name="t_admin_user")
public class AdminUser implements Serializable {
	
	public static final String _DEFULTPWD="123456"; //用户默认密码
	
    private Integer id;

    private String userName;

    private String password=_DEFULTPWD;
    
    private String salt;
    
    @FieldFormart(clazz=RoleService.class,method="getUserRoles",paramsType={AdminUser.class})
    private List<Role> roles;

    public AdminUser() {
    	salt=String.valueOf(RandomUtils.nextInt(1000));
    }

    public void setId(Integer id) {
        this.id = id;
    }
    @Id
    public Integer getId() {
        return id;
    }

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public void setPassword(String password) {
        this.password = password;
    }

    public String getPassword() {
        return password;
    }

	public String getSalt() {
		return salt;
	}

	public void setSalt(String salt) {
		this.salt = salt;
	}
	 @Transient
	public List<Role> getRoles() {
		if(null==roles||roles.size()==0){
			Object o= BeanUtil.fieldFormat(this,"roles",this);
			roles=(List<Role>) o;
		}
		return roles;
	}

	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}
    

}
